package com.imooc.distributedemo.rithm;

import java.util.Stack;

// 对比字符串中的括号 {}()[] 是否对称
public class SysmbolSolution {

    public static boolean isValid(String s){
        Stack<Integer> p = new Stack();
        for (int i = 0; i < s.length(); i++) {
            int q= "(){}[]".indexOf(s.substring(i,i+1));
            if(q%2==1){
                if(p.isEmpty()||p.pop()!=q-1){
                    return false;
                }else{
                    p.push(q);
                }
            }
        }
        return p.isEmpty();
    }

    public static void main(String[] args) {
        String s = "{{()[[}}";
        boolean result = isValid(s);
        System.out.println(result);
    }
}
